package com.cqhfan.chatroom.controller;

import com.cqhfan.chatroom.domain.dto.LoginFormDTO;
import com.cqhfan.chatroom.domain.vo.CaptchaVO;
import com.cqhfan.chatroom.domain.vo.UserLoginVO;
import com.cqhfan.chatroom.service.IUserService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * @author 眭传洪
 * @create 2024-11-14 19:39
 */
@Tag(name = "权限相关接口")
@RestController
@RequestMapping("/auth")
@RequiredArgsConstructor
public class AuthController {

    private final IUserService userService;

    @Operation(summary = "生成验证码")
    @GetMapping("/generatorCaptcha/{width}/{height}")
    public CaptchaVO generatorCaptcha(@PathVariable("width") Integer width, @PathVariable("height") Integer height) {
        return userService.generatorCaptcha(width, height);
    }

    @Operation(summary = "发送验证码")
    @GetMapping("/sendCode/{phoneNumber}")
    public void sendCode(@PathVariable("phoneNumber") String phoneNumber) {
        userService.sendCode(phoneNumber);
    }

    @Operation(summary = "登录")
    @PostMapping("/login")
    public UserLoginVO login(@RequestBody LoginFormDTO dto) {
        return userService.login(dto);
    }

    @Operation(summary = "退出登录")
    @PostMapping("/logout")
    public void logout(@RequestHeader("refreshToken") String refreshToken) {
        userService.logout(refreshToken);
    }

    @Operation(summary = "刷新token")
    @PostMapping("/refreshToken")
    public UserLoginVO login(@RequestHeader("refreshToken") String refreshToken) {
        return userService.refreshToken(refreshToken);
    }

}
